package isc.authclt;

import isc.log.IscLog;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;

public class AuthClient
  implements CryptProHead, CryptErrHead
{
  private int logLevel = 1;
  private CryptPro cryptPro;
  private int ibBuffer = 4096;
  private byte[] bBuffer = new byte[100];
  private IscLog authClientLog = new IscLog();
  private BusyFlag bf = new BusyFlag();

  private void debug(Object paramObject)
  {
    if (this.logLevel != 0)
      System.out.println(DateFormat.getDateTimeInstance().format(new Date()) + ":" + paramObject);
  }

  public AuthClient()
  {
    this.cryptPro = new CryptPro();
  }

  public SocketData Crypt_OpenDevice(String paramString1, String paramString2, int paramInt1, int paramInt2)
  {
    SocketPool localSocketPool = SocketPool.getInstance();
    SocketData localSocketData = null;
    try
    {
      localSocketData = localSocketPool.getSocket();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return localSocketData;
  }

  public SocketData Crypt_OpenDevice(String paramString1, String paramString2, int paramInt1, String paramString3, int paramInt2)
  {
    int i = paramString2.indexOf(",");
    if (i != -1)
    {
      SocketPool.setNoAuthCltFlag();
      String localObject = paramString2.substring(i + 1);
      System.out.println((String)localObject);
      paramString2 = paramString2.substring(0, i);
      System.out.println(paramString2);
      SocketPool.setStrServerHost((String)localObject);
    }
    Object localObject = SocketPool.getInstance();
    SlotData localSlotData = ((SocketPool)localObject).getSlotData();
    int j = ((SocketPool)localObject).getSocketCount();
    SocketData localSocketData = null;
    for (int k = 0; k < j + 1; ++k)
    {
      try
      {
        localSocketData = ((SocketPool)localObject).getSocketData();
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
      }
      if (localSocketData.getErrCode() == 0)
      {
        if (!(paramString3.equals(localSlotData.user_pin.toString())))
        {
          localSocketData.setErrCode(168);
          return localSocketData;
        }
        if (!(paramString1.equals(localSlotData.szContainer)))
          localSocketData.setErrCode(36);
        if (!(paramString2.equals(localSlotData.szProvider)))
          localSocketData.setErrCode(34);
      }
      localSocketData.lock();
      if (!(localSocketData.isConnected()))
        break;
      int l = TestServer(localSocketData);
      if (l == 0)
        break;
      Crypt_failed(localSocketData);
    }
    return ((SocketData)localSocketData);
  }

  public SocketData Crypt_OpenDevice(int paramInt)
  {
    SocketPool localSocketPool = SocketPool.getInstance();
    SocketData localSocketData = null;
    try
    {
      localSocketData = localSocketPool.getSocketData(paramInt);
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    localSocketData.lock();
    return localSocketData;
  }

  public void Crypt_CloseDevice(SocketData paramSocketData)
  {
    SocketPool localSocketPool = SocketPool.getInstance();
    localSocketPool.free(paramSocketData);
    paramSocketData.unlock();
    paramSocketData = null;
  }

  private void Crypt_failed(SocketData paramSocketData)
  {
    SocketPool localSocketPool = SocketPool.getInstance();
    localSocketPool.failed(paramSocketData);
    paramSocketData.unlock();
    paramSocketData = null;
  }

  public int TestServer(SocketData paramSocketData)
  {
    int i = 0;
    int j = 8;
    String str = "TEST";
    RecvData localRecvData = new RecvData();
    Template[] arrayOfTemplate = { new Template(5, str.getBytes(), 4) };
    int k = arrayOfTemplate.length;
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate, k, localRecvData);
    if (i != 0)
      return i;
    return i;
  }

  public int Crypt_Send_Receive(SocketData paramSocketData, int paramInt1, Template[] paramArrayOfTemplate, int paramInt2, RecvData paramRecvData)
  {
    int i = 0;
    int j = 30000;
    if (paramSocketData == null)
      return (i = 95);
    byte[] arrayOfByte1 = this.cryptPro.Crypt_Encode_Packet(paramInt1, paramArrayOfTemplate, paramInt2);
    try
    {
      i = this.cryptPro.sendRecvMac(paramSocketData, arrayOfByte1, arrayOfByte1.length, null, paramRecvData, j);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    if (i != 0)
    {
      Crypt_failed(paramSocketData);
      return i;
    }
    byte[] arrayOfByte2 = paramRecvData.getRecvData();
    Packet localPacket = this.cryptPro.decode_head(arrayOfByte2);
    paramRecvData.setReceiveLen(localPacket.len);
    paramRecvData.setRecvData(arrayOfByte2, 4, localPacket.len);
    if (localPacket.flags != 0)
      i = this.cryptPro.GetErrorFromBuffer(paramRecvData);
    return i;
  }

  public int Crypt_ReadCert(SocketData paramSocketData, int paramInt, RecvData paramRecvData)
    throws Exception
  {
    int i = 0;
    int j = 36;
    int k = 2048;
    byte[] arrayOfByte = new byte[k];
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt), new Template(6, arrayOfByte, k) };
    int l = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, l, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_ReadPublicKey(SocketData paramSocketData, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    byte[] arrayOfByte = new byte[256];
    int j = 256;
    int k = 38;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt), new Template(6, arrayOfByte, j) };
    int l = 2;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, k, arrayOfTemplate1, l, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_GenRandom(SocketData paramSocketData, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    int j = 37;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt), new Template(6, this.bBuffer, paramInt) };
    int k = 2;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_Hash(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt1, int paramInt2, RecvData paramRecvData)
  {
    int i = 0;
    int j = 40;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt1), new Template(4, null, paramInt2), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_GenSecKey(SocketData paramSocketData, int paramInt1, int paramInt2, RecvData paramRecvData)
  {
    int i = 0;
    int j = 57;
    int k = 0;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt1), new Template(4, null, paramInt2), new Template(4, null, k) };
    int l = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, l, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_DestroyKey(SocketData paramSocketData, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    int j = 60;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    return i;
  }

  public int Crypt_Encrypt(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 53;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(6, this.bBuffer, this.ibBuffer + paramInt1), new Template(5, paramArrayOfByte2, paramInt3) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_Decrypt(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 55;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(6, this.bBuffer, this.ibBuffer + paramInt1), new Template(5, paramArrayOfByte2, paramInt3) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_EncryptEx(SocketData paramSocketData, int paramInt1, byte[] paramArrayOfByte, int paramInt2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 54;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt1), new Template(5, paramArrayOfByte, paramInt2), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_DecryptEx(SocketData paramSocketData, int paramInt1, byte[] paramArrayOfByte, int paramInt2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 56;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt1), new Template(5, paramArrayOfByte, paramInt2), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_ClientHello(SocketData paramSocketData, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    int j = 72;
    Template[] arrayOfTemplate1 = { new Template(4, null, paramInt), new Template(6, new byte[100], 1000) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_ClientAuth(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    int j = 74;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_ServerHello(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt, RecvData paramRecvData)
  {
    this.authClientLog.printf("AuthClient.Crypt_ServerHello()--begin!");
    int j = 0;
    int k = 73;
    byte[] arrayOfByte = new byte[16];
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt), new Template(6, this.bBuffer, this.ibBuffer), new Template(6, this.bBuffer, 16) };
    int l = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    j = Crypt_Send_Receive(paramSocketData, k, arrayOfTemplate1, l, paramRecvData);
    if (j != 0)
      return j;
    j = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (j != 0)
      return j;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    System.arraycopy(arrayOfTemplate2[1].bValue, 0, arrayOfByte, 0, 16);
    arrayOfByte[0] = (byte)paramSocketData.slot_idx;
    arrayOfByte[1] = (byte)paramSocketData.host_idx;
    arrayOfByte[2] = 86;
    arrayOfByte[3] = 49;
    for (int i = 4; i < 16; ++i)
    {
      int tmp237_235 = i;
      byte[] tmp237_233 = arrayOfByte;
      tmp237_233[tmp237_235] = (byte)(tmp237_233[tmp237_235] ^ 0xFF);
    }
    paramRecvData.setRecvData1(arrayOfByte);
    paramRecvData.setReceiveLen1(16);
    this.authClientLog.printf("AuthClient.Crypt_ServerHello()--end!");
    return j;
  }

  public int Crypt_ServerAuth(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2, RecvData paramRecvData)
  {
    this.authClientLog.printf("AuthClient.Crypt_ServerAuth()--begin!");
    int i = 0;
    int j = 75;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(5, paramArrayOfByte2, paramInt2), new Template(6, this.bBuffer, this.ibBuffer), new Template(6, this.bBuffer, 16) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    if ((paramArrayOfByte2 != null) && (paramInt2 >= 3))
      while (true)
      {
        if (paramSocketData.host_idx == paramArrayOfByte2[1])
          break;
        Crypt_CloseDevice(paramSocketData);
        paramSocketData = Crypt_OpenDevice(paramArrayOfByte2[1]);
      }
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    paramRecvData.setRecvData1(arrayOfTemplate2[1].bValue);
    paramRecvData.setReceiveLen1(arrayOfTemplate2[1].valueLen);
    Crypt_CloseDevice(paramSocketData);
    this.authClientLog.printf("AuthClient.Crypt_ServerAuth()--end!");
    return i;
  }

  public int Crypt_DigestData(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 64;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt1), new Template(4, null, paramInt2), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_VerifyDigestedData(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2)
  {
    int i = 0;
    int j = 65;
    RecvData localRecvData = new RecvData();
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(5, paramArrayOfByte2, paramInt2), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, localRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(localRecvData.getRecvData(), localRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    return i;
  }

  public int Crypt_VerifySign(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, int paramInt3, byte[] paramArrayOfByte2, int paramInt4, byte[] paramArrayOfByte3, int paramInt5)
  {
    int i = 0;
    int j = 50;
    byte[] arrayOfByte = new byte[20];
    RecvData localRecvData = new RecvData();
    Template[] arrayOfTemplate = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(4, null, paramInt3), new Template(5, paramArrayOfByte2, paramInt4), new Template(5, paramArrayOfByte3, paramInt5) };
    int k = arrayOfTemplate.length;
    if ((paramInt1 > 2000) && (paramArrayOfByte1 != null) && (paramInt1 != 0))
    {
      String str = getAlgorithm(6);
      if (str == null)
        return 57;
      arrayOfByte = Crypt_Hash(paramArrayOfByte1, str, paramInt1);
      arrayOfTemplate[0].bValue = arrayOfByte;
      arrayOfTemplate[0].valueLen = arrayOfByte.length;
    }
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate, k, localRecvData);
    return i;
  }

  public int Crypt_SignAlgIdToHashAlgId(int paramInt)
  {
    int i = -1;
    if (paramInt == 5)
      i = 528;
    else if (paramInt == 6)
      i = 544;
    else if (paramInt == 1)
      i = 0;
    else
      i = 57;
    return i;
  }

  public String getAlgorithm(int paramInt)
  {
    String str = null;
    if ((paramInt == 5) || (paramInt == 528))
      str = "MD5";
    else if ((paramInt == 6) || (paramInt == 544))
      str = "SHA";
    return str;
  }

  public byte[] Crypt_Hash(byte[] paramArrayOfByte, String paramString)
  {
    MessageDigest localMessageDigest = null;
    try
    {
      localMessageDigest = MessageDigest.getInstance(paramString);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      localNoSuchAlgorithmException.printStackTrace();
      return null;
    }
    byte[] arrayOfByte = localMessageDigest.digest(paramArrayOfByte);
    return arrayOfByte;
  }

  public byte[] Crypt_Hash(byte[] paramArrayOfByte, String paramString, int paramInt)
  {
    MessageDigest localMessageDigest = null;
    try
    {
      localMessageDigest = MessageDigest.getInstance(paramString);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      localNoSuchAlgorithmException.printStackTrace();
      return null;
    }
    localMessageDigest.update(paramArrayOfByte, 0, paramInt);
    byte[] arrayOfByte = localMessageDigest.digest();
    return arrayOfByte;
  }

  public int Crypt_Sign(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 48;
    byte[] arrayOfByte = new byte[20];
    int k = 20;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt1), new Template(4, null, paramInt2), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int l = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    if (paramInt1 > 2000)
    {
      String str = getAlgorithm(paramInt2);
      if (str == null)
        return 57;
      arrayOfByte = Crypt_Hash(paramArrayOfByte, str, paramInt1);
      arrayOfTemplate1[0].bValue = arrayOfByte;
      arrayOfTemplate1[0].valueLen = arrayOfByte.length;
      arrayOfTemplate1[3].valueLen |= 16;
    }
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, l, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_SignHash(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 49;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt1), new Template(4, null, paramInt2), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_SignData(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 66;
    byte[] arrayOfByte = new byte[20];
    int k = 20;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(5, paramArrayOfByte2, paramArrayOfByte2.length), new Template(4, null, paramInt3), new Template(6, this.bBuffer, this.ibBuffer) };
    int l = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    if ((paramInt1 > 2000) && ((paramInt3 & 0x1) == 0) && ((paramInt3 & 0x10) == 0))
    {
      String str = getAlgorithm(paramInt2);
      if (str == null)
        return 57;
      arrayOfByte = Crypt_Hash(paramArrayOfByte1, str, paramInt1);
      arrayOfTemplate1[0].bValue = arrayOfByte;
      arrayOfTemplate1[0].valueLen = arrayOfByte.length;
      arrayOfTemplate1[3].valueLen |= 16;
    }
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, l, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_VerifySignedData(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, byte[] paramArrayOfByte3, int paramInt4)
  {
    int i = 0;
    int j = 67;
    byte[] arrayOfByte = new byte[20];
    RecvData localRecvData = new RecvData();
    Template[] arrayOfTemplate = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(5, paramArrayOfByte2, paramInt3), new Template(5, paramArrayOfByte3, paramInt4) };
    int k = arrayOfTemplate.length;
    if ((paramInt3 > 2000) && (paramArrayOfByte2 != null) && (paramInt3 != 0) && ((paramInt2 & 0x10) == 0))
    {
      String str = getAlgorithm(6);
      if (str == null)
        return 57;
      arrayOfByte = Crypt_Hash(paramArrayOfByte2, str, paramInt3);
      arrayOfTemplate[2].bValue = arrayOfByte;
      arrayOfTemplate[2].valueLen = arrayOfByte.length;
      arrayOfTemplate[1].valueLen |= 16;
    }
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate, k, localRecvData);
    return i;
  }

  public int Crypt_EnvelopData(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3, int paramInt4, byte[] paramArrayOfByte3, int paramInt5, RecvData paramRecvData)
  {
    int i = 0;
    int j = 68;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(4, null, paramInt2), new Template(5, paramArrayOfByte2, paramInt3), new Template(4, null, paramInt4), new Template(5, paramArrayOfByte3, paramArrayOfByte3.length), new Template(4, null, paramInt5), new Template(6, this.bBuffer, paramInt1 + 2000) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_VerifyEnvelopedData(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2, byte[] paramArrayOfByte3, int paramInt3, RecvData paramRecvData)
  {
    int i = 0;
    int j = 69;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(5, paramArrayOfByte2, paramInt2), new Template(5, paramArrayOfByte3, paramInt3), new Template(6, this.bBuffer, paramInt1 + 2000) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_GetCertStatus(SocketData paramSocketData, byte[] paramArrayOfByte, int paramInt1, int paramInt2, RecvData paramRecvData)
  {
    int i = 0;
    int j = 79;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte, paramInt1), new Template(5, null, paramInt2), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_GetUserPublicKey(SocketData paramSocketData, byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2, RecvData paramRecvData)
  {
    int i = 0;
    int j = 76;
    Template[] arrayOfTemplate1 = { new Template(5, paramArrayOfByte1, paramInt1), new Template(5, paramArrayOfByte2, paramInt2), new Template(6, this.bBuffer, this.ibBuffer) };
    int k = arrayOfTemplate1.length;
    Template[] arrayOfTemplate2 = new Template[3];
    int[] arrayOfInt = { 3 };
    i = Crypt_Send_Receive(paramSocketData, j, arrayOfTemplate1, k, paramRecvData);
    if (i != 0)
      return i;
    i = this.cryptPro.CryptGetTemplateFromBuffer(paramRecvData.getRecvData(), paramRecvData.getRecvLen(), arrayOfTemplate2, arrayOfInt);
    if (i != 0)
      return i;
    paramRecvData.setRecvData(arrayOfTemplate2[0].bValue);
    paramRecvData.setReceiveLen(arrayOfTemplate2[0].valueLen);
    return i;
  }

  public int Crypt_AlgNameToAlgId(String paramString)
  {
    if (paramString.equals("MD5"))
      return 528;
    if (paramString.equals("SHA1"))
      return 544;
    if (paramString.equals("RSA"))
      return 1;
    if (paramString.equals("MD5withRSA"))
      return 5;
    if (paramString.equals("SHA1withRSA"))
      return 6;
    if (paramString.equals("RC4"))
      return 273;
    if (paramString.equals("DES3_CBC"))
      return 307;
    if (paramString.equals("SSF33"))
      return -2147479455;
    if (paramString.equals("GBSSF33"))
      return 513;
    if (paramString.equals("GBSSF33_CBC"))
      return 514;
    if (paramString.equals("GBSM1"))
      return 257;
    if (paramString.equals("GBSM1_CBC"))
      return 258;
    if (paramString.equals("GBSMS4"))
      return 1025;
    if (paramString.equals("GBSMS4_CBC"))
      return 1026;
    if (paramString.equals("GBSM3"))
      return 33;
    if (paramString.equals("GBECC"))
      return 16;
    if (paramString.equals("GBECSM3"))
      return 23;
    if (paramString.equals("IDEA_CBC"))
      return 834;
    return 58;
  }

  public int Crypt_HashFile(String paramString, int paramInt, RecvData paramRecvData)
  {
    int i = 0;
    byte[] arrayOfByte1 = null;
    try
    {
      try
      {
        try
        {
          FileInputStream localFileInputStream = new FileInputStream(paramString);
          byte[] arrayOfByte2 = new byte[this.ibBuffer];
          int j = 0;
          String str = getAlgorithm(paramInt);
          if (str == null)
            return 57;
          MessageDigest localMessageDigest = MessageDigest.getInstance(str);
          while (true)
          {
            j = localFileInputStream.read(arrayOfByte2);
            if (j == -1)
              break;
            localMessageDigest.update(arrayOfByte2, 0, j);
          }
          arrayOfByte1 = localMessageDigest.digest();
          paramRecvData.setRecvData(arrayOfByte1);
          paramRecvData.setReceiveLen(arrayOfByte1.length);
        }
        catch (FileNotFoundException localFileNotFoundException)
        {
          i = 13;
          localFileNotFoundException.printStackTrace();
        }
      }
      catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
      {
        i = 57;
        localNoSuchAlgorithmException.printStackTrace();
      }
    }
    catch (IOException localIOException)
    {
      i = 20;
      localIOException.printStackTrace();
    }
    return i;
  }

  public void clean()
    throws IOException
  {
  }

  protected void finalize()
    throws Throwable
  {
  }

  public String byteToHex(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if (paramArrayOfByte == null)
      return null;
    for (int i = 0; i < paramArrayOfByte.length; ++i)
      if ((paramArrayOfByte[i] & 0xF0) == 0)
        localStringBuffer.append("0" + Integer.toHexString(paramArrayOfByte[i] & 0xFF));
      else
        localStringBuffer.append(Integer.toHexString(paramArrayOfByte[i] & 0xFF));
    return localStringBuffer.toString();
  }

  public byte[] getCurrentDateTime()
  {
    byte[] arrayOfByte = new byte[8];
    Calendar localCalendar = Calendar.getInstance();
    int i = localCalendar.get(1);
    arrayOfByte[0] = (byte)(i >> 8 & 0xFF);
    arrayOfByte[1] = (byte)(i & 0xFF);
    arrayOfByte[2] = (byte)(localCalendar.get(2) + 1);
    arrayOfByte[3] = (byte)localCalendar.get(5);
    arrayOfByte[4] = (byte)localCalendar.get(11);
    arrayOfByte[5] = (byte)localCalendar.get(12);
    arrayOfByte[6] = (byte)localCalendar.get(13);
    arrayOfByte[7] = 0;
    return arrayOfByte;
  }

  public void test_auth(RecvData paramRecvData)
  {
    int i = 0;
    SocketData localSocketData1 = Crypt_OpenDevice("Slot1", "authclt", 1540, "88880001", 0);
    if (localSocketData1.getErrCode() != 0)
      System.out.println(CryptError.Crypt_GetErrorMsg(localSocketData1.getErrCode()));
    i = Crypt_ClientHello(localSocketData1, 0, paramRecvData);
    if (i != 0)
    {
      System.out.println("Crypt_ClientHello:err1=" + i);
      System.out.println(CryptError.Crypt_GetErrorMsg(i));
    }
    Crypt_CloseDevice(localSocketData1);
    SocketData localSocketData2 = Crypt_OpenDevice("Slot1", "authclt", 1540, "88880001", 0);
    i = Crypt_ServerHello(localSocketData2, paramRecvData.getRecvData(), paramRecvData.getRecvLen(), paramRecvData);
    if (i != 0)
    {
      System.out.println("Crypt_ServerHello:err=" + i);
      System.out.println(CryptError.Crypt_GetErrorMsg(i));
    }
    Crypt_CloseDevice(localSocketData2);
    SocketData localSocketData3 = Crypt_OpenDevice("Slot1", "authclt", 1540, "88880001", 0);
    i = Crypt_ClientAuth(localSocketData3, paramRecvData.getRecvData(), paramRecvData.getRecvLen(), paramRecvData);
    if (i != 0)
    {
      System.out.println("Crypt_ClientAuth:err=" + i);
      System.out.println(CryptError.Crypt_GetErrorMsg(i));
    }
    Crypt_CloseDevice(localSocketData3);
    SocketData localSocketData4 = Crypt_OpenDevice("Slot1", "authclt", 1540, "88880001", 0);
    i = Crypt_ServerAuth(localSocketData4, paramRecvData.getRecvData(), paramRecvData.getRecvLen(), paramRecvData.getRecvData1(), paramRecvData.getRecvLen1(), paramRecvData);
    if (i != 0)
    {
      System.out.println("Crypt_ServerAuth:err=" + i);
      System.out.println(CryptError.Crypt_GetErrorMsg(i));
    }
    Crypt_CloseDevice(localSocketData4);
  }

  public static void main(String[] paramArrayOfString)
    throws InterruptedException
  {
    int i = 1;
    for (int j = 0; j < i; ++j)
    {
      AuthClient localAuthClient = new AuthClient();
      RecvData localRecvData = new RecvData();
      Object localObject = null;
      try
      {
        try
        {
          localAuthClient.test_auth(localRecvData);
        }
        catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
        {
          localArrayIndexOutOfBoundsException.printStackTrace();
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }
  }
}